{% extends "base.html" %}
{%- import "header/package_navigation.html" as navigation -%}

{%- block title -%}
    {% call macros::doc_title(name=metadata.name, version=metadata.version) %}
{%- endblock title -%}

{%- block meta -%}
<link rel="canonical" href="{{ canonical_url|safe }}" />
{%- endblock -%}

{%- block topbar -%}
  {%- include "rustdoc/topbar.html" -%}
{%- endblock topbar -%}

{%- block header -%}
    {% call navigation::package_navigation(metadata=metadata, active_tab="features") %}
{%- endblock header -%}

{%- block body -%}
    <div class="container package-page-container">
        <div class="pure-g">
            <div class="pure-u-1 pure-u-sm-7-24 pure-u-md-5-24">
                <div class="pure-menu package-menu">
                    <ul class="pure-menu-list">
                        <li class="pure-menu-heading">Feature flags</li>
                        {%- if let Some(features) = sorted_features -%}
                            {%- if features.is_empty() -%}
                                <li class="pure-menu-item">
                                   <span class="documented-info">This release does not have any feature flags.</span>
                                </li>
                            {%- else %}
                                {%- for feature in features -%}
                                    <li class="pure-menu-item">
                                        <a href="#{{ feature.name }}" class="pure-menu-link text-center">
                                            {{- feature.name -}}
                                        </a>
                                    </li>
                                {%- endfor %}
                            {%- endif -%}
                        {%- else -%}
                            <li class="pure-menu-item">
                                <span class="documented-info">
                                    Feature flags are not available for this release because the build failed before we could retrieve them,
                                    or it was built before features were collected by docs.rs.
                                </span>
                            </li>
                        {%- endif -%}
                    </ul>
                </div>
            </div>

            <div class="pure-u-1 pure-u-sm-17-24 pure-u-md-19-24 package-details" id="main">
                <h1>{{ metadata.name }}</h1>
                <div class="info">
                    There is very little structured metadata to build this page
                    from currently. You should check the
                    <a href="{{ params.rustdoc_url() }}">main library docs</a>,
                    <a href="{{ params.crate_details_url() }}">readme</a>, or
                    <a href="{{ params.clone().with_inner_path("Cargo.toml.orig").with_page_kind(PageKind::Source).source_url() }}">Cargo.toml</a>
                    in case the author documented the features in them.
                </div>
                {%- if let Some(features) = sorted_features -%}
                    {%- if features.is_empty() -%}
                        <p data-id="empty-features">This release does not have any feature flags.</p>
                    {%- else -%}
                        <p>This version has <b>{{ features_count() }}</b> feature flags, <b data-id="default-feature-len">{{ enabled_default_features_count() }}</b> of them enabled by <b>default</b>.</p>
                        {%- for feature in features -%}
                            {%- let is_default = feature.name != "default" && is_default_feature(feature.name) -%}
                            <h3 id="{{ feature.name }}">{{ feature.name }}{%- if is_default  %} (default){%- endif -%}</h3>
                            {%- if !feature.subfeatures.is_empty() -%}
                                <ul class="pure-menu-list">
                                    {%- for (name, feature) in feature.subfeatures -%}
                                        {%- let is_default = is_default_feature(name) -%}
                                        <li class="pure-menu-item">
                                            {%- match feature -%}
                                                {%- when SubFeature::Feature with (feature) -%}
                                                    <a href="#{{ feature }}">
                                                        {{- feature -}}
                                                    </a>
                                                {% when SubFeature::Dependency with (dependency) %}
                                                    {%- let version = dependency_version(dependency) -%}
                                                        dep:<a href="{{ RustdocParams::new(dependency.to_owned()).with_req_version(version.to_owned()).rustdoc_url() }}">
                                                        {{- dependency -}}
                                                    </a>
                                                {% when SubFeature::DependencyFeature with {dependency, feature, optional} %}
                                                    {%- let version = dependency_version(dependency) -%}
                                                    {%- set dependency_params = RustdocParams::new(dependency.to_owned()).with_req_version(version.to_owned()) -%}
                                                    <a href="{{ dependency_params.crate_details_url() }}">
                                                        {{- dependency -}}
                                                    </a>
                                                    {%- if optional -%}?{%- endif -%}
                                                    /<a href="{{ dependency_params.features_url().with_fragment(*feature) }}">
                                                        {{- feature -}}
                                                    </a>
                                            {%- endmatch %}
                                            {%- if is_default %} <span class="is-default-feature">(default)</span>{%- endif -%}
                                        </li>
                                    {%- endfor -%}
                                </ul>
                            {%- else -%}
                                <p>This feature flag does not enable additional features.</p>
                            {%- endif -%}
                        {%- endfor -%}
                    {% endif -%}
                {% else -%}
                    <p data-id="null-features">Feature flags are not available for this release because it was built before features were collected by docs.rs.</p>
                {%- endif -%}
            </div>
        </div>
    </div>
{%- endblock body -%}
